package com.yh.csx.bsf.flow.engine.state;

import com.yh.csx.bsf.flow.provider.enums.FlowStateEnum;
import com.yh.csx.bsf.flow.core.db.DbHelper;
import com.yh.csx.bsf.flow.dao.dal.t_task_dal;
import com.yh.csx.bsf.flow.dao.model.auto.t_approve_log_model;
import lombok.val;

import java.util.Date;

/**
 * @author: chejiangyi
 * @version: 2019-10-28 18:39
 **/
public class EndNode extends BaseNode{
    @Override
    public String getName(){
        return "结束";
    }
    @Override
    public void flow(int flowid){
        try
        {
            logFlowDebug(flowid,"节点:结束 进入流转");
            beginScript(flowid);
            //关闭流程任务
            DbHelper.get((c)->new t_task_dal().closedAllTasks(c,flowid,"系统"));
            //记录日志
            val model = new t_approve_log_model(0,flowid,0,"","",getName(),"0",new Date(),"系统",new Date(),"系统","系统");
            addApproveLog(model);
            //更新流程状态
            refreshFlowApprove(flowid);
            updateFlowState(flowid, FlowStateEnum.done.Value);
            logFlowDebug(flowid,"节点:结束 流程正常结束");
        }catch (Exception e){
            throw filterException(flowid,e);
        }
    }
}
